﻿using System;
using System.ComponentModel;
using CodeSnippet.Properties;

namespace CodeSnippet.Options
{
    /// <summary>
    /// Localized <see cref="CategoryAttribute"/>.
    /// </summary>
    [AttributeUsage(AttributeTargets.Field | AttributeTargets.Property)]
    public sealed class LocalizedCategoryAttribute : CategoryAttribute
    {
        #region Initilization
        /// <summary>
        /// Initializes a new instance of the <see cref="LocalizedCategoryAttribute"/> class.
        /// </summary>
        /// <param name="category">The name of the category.</param>
        public LocalizedCategoryAttribute(string category) : base(category)
        {
        }
        #endregion Initilization

        #region Overrides
        /// <summary>
        /// Looks up the localized name of the specified category.
        /// </summary>
        /// <param name="value">The identifer for the category to look up.</param>
        /// <returns>
        /// The localized name of the category, or null if a localized name does not exist.
        /// </returns>
        protected override string GetLocalizedString(string value)
        {
            // Return the localized version of the given value.
            var str = Resources.ResourceManager.GetString(value, Resources.Culture);
            return str ?? value;
        }
        #endregion Overrides
    }
}